package de.fhaugsburg.games.boardgames.scrabble.consoleui;

import de.fhaugsburg.games.boardgames.exceptions.GameException;
import de.fhaugsburg.games.boardgames.scrabble.ScrabbleBoard;

/**
 * BoardView is used to print a scrabbleboard to the console with a marking with letter and numbers.
 * 
 * @author r4smus
 * 
 */
public class BoardView {

	private ScrabbleBoard board;
	private String rowLetters = "ABCDEFGHIJKLMNO";
	private String columnNumbers = "  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15";

	public BoardView(ScrabbleBoard board) {
		this.board = board;
	}

	public void render() throws GameException {
		System.out.println(columnNumbers);

		for (int row = 0; row < board.getHeight(); row++) {

			System.out.print(rowLetters.charAt(row));

			for (int column = 0; column < board.getWidth(); column++) {

				if (board.isEmpty(row, column))
					System.out.print(board.getDetails(row, column).toString());
				else
					System.out.print(" " + board.getPiece(row, column).toString().toLowerCase() + " ");

			}
			System.out.print(rowLetters.charAt(row));
			System.out.println();

		}
		System.out.println(columnNumbers);

	}

}
